package cn.com.ddapp.ddm.fragment.base;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.bumptech.glide.Glide;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.MainActivity;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.BrandRevelryAdapter;
import cn.com.ddapp.ddm.adapter.BrandRevelryLandAdapter;
import cn.com.ddapp.ddm.adapter.BrannlistAdpter;
import cn.com.ddapp.ddm.adapter.ChaotejiaAdpter;
import cn.com.ddapp.ddm.adapter.ClassFicationRootAdpter;
import cn.com.ddapp.ddm.adapter.ClassFicationSortAdpter;
import cn.com.ddapp.ddm.adapter.ClassifyGoodHomeAdpter;
import cn.com.ddapp.ddm.adapter.ClassifyGoodLandAdpter;
import cn.com.ddapp.ddm.adapter.GuessAdapter;
import cn.com.ddapp.ddm.adapter.HomePagerAdapter;
import cn.com.ddapp.ddm.adapter.LandGuessAdapter;
import cn.com.ddapp.ddm.adapter.LandProAdapter;
import cn.com.ddapp.ddm.adapter.LimitImgAdapter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.ATMaddressBean;
import cn.com.ddapp.ddm.bean.ATMcode;
import cn.com.ddapp.ddm.bean.AreaBean;
import cn.com.ddapp.ddm.bean.Banner;
import cn.com.ddapp.ddm.bean.BrannlistBean;
import cn.com.ddapp.ddm.bean.ClassifyGoodBean;
import cn.com.ddapp.ddm.bean.GoodSmallSortBean;
import cn.com.ddapp.ddm.bean.HomeBean;
import cn.com.ddapp.ddm.fragment.base.landgoods.EightFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.FeatureFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.FestivaFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.FirecrackerFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.GuoNianFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.NineFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.ProtectionFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.SevenFragment;
import cn.com.ddapp.ddm.fragment.base.landgoods.SixFragment;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.BrandListActivity;
import cn.com.ddapp.ddm.ui.CommidContentActivity;
import cn.com.ddapp.ddm.ui.GoodClassifyActivity;
import cn.com.ddapp.ddm.ui.GoodLandClassifyActivity;
import cn.com.ddapp.ddm.ui.LimitTimeGoActivity;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.BannerUtil;
import cn.com.ddapp.ddm.util.CountDownTimer;
import cn.com.ddapp.ddm.util.DividerGridItemDecoration;
import cn.com.ddapp.ddm.util.HomeBannerUtil;
import cn.com.ddapp.ddm.util.NetUtils;
import cn.com.ddapp.ddm.util.RecycleViewDivider;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.TDevice;
import cn.com.ddapp.ddm.util.TLog;
import cn.com.ddapp.ddm.util.ToastUtil;
import okhttp3.Call;

/**
 * Created by Administrator on 2016/8/29 0029.//横屏的主页面
 */
public class LandHomePagerFragment extends BaseFragment {
    @BindView(R.id.homePager)
    ViewPager homePager;
    @BindView(R.id.frameLayout)
    AutoFrameLayout frameLayout;
    @BindView(R.id.one)
    RadioButton one;
    @BindView(R.id.two)
    RadioButton two;
    @BindView(R.id.three)
    RadioButton three;
    @BindView(R.id.four)
    RadioButton four;
    @BindView(R.id.five)
    RadioButton five;
    @BindView(R.id.six)
    RadioButton six;
    @BindView(R.id.seven)
    RadioButton seven;
    @BindView(R.id.eight)
    RadioButton eight;
    @BindView(R.id.nine)
    RadioButton nine;
    @BindView(R.id.land_more)
    RadioButton landMore;
    @BindView(R.id.landFrame)
    AutoFrameLayout landFrame;
    @BindView(R.id.tosortList)
    AutoRelativeLayout tosortList;
    @BindView(R.id.revelry)
    RecyclerView revelry;
    @BindView(R.id.lifefayout)
    AutoLinearLayout lifefayout;
    @BindView(R.id.rightLayput)
    AutoFrameLayout rightLayput;
    @BindView(R.id.buttomView)
    RecyclerView buttomView;
    @BindView(R.id.error_layout)
    EmptyLayout mEmptyLayout;
    @BindView(R.id.land_radio)
    RadioGroup landRadio;
    @BindView(R.id.llDots)
    LinearLayout llDots;
    @BindView(R.id.fenRecycler)
    GridView fenRecycler;
    @BindView(R.id.timerView)
    CountDownTimer timerView;
    @BindView(R.id.land_xian_ll)
    LinearLayout land_xian_ll;
    @BindView(R.id.xianshi_view)
    RecyclerView xianshi_view;
    @BindView(R.id.tejia_view)
    GridView tejia_view;
    @BindView(R.id.land_h_city)
    TextView land_h_city;
    //    @BindView(R.id.index_mapview)
//    MapView mMapView;
    AMap aMap;
    private LocationSource.OnLocationChangedListener mListener;
    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;
    private HomeBean homeBean;
    private List<HomeBean.BannerListBean> bannerListBeen;
    private Fragment currentFragment;
    private FestivaFragment festivaFragment;
    private FragmentManager fragmentManager;
    private boolean Looper = true;
    private List<ImageView> ivs = new ArrayList<>();
    public int perPosition;
    private Intent intent;
    private int sortType;
    private List<GoodSmallSortBean.GoodSmallSort> slist;
    private ClassFicationSortAdpter sAdapter;
    private ClassFicationRootAdpter rAdapter;
    private ClassifyGoodHomeAdpter cAdapter;
    private ClassifyGoodLandAdpter landcAdapter;
    private List<ClassifyGoodBean.ClassifyGood> nnList;
    // 天 ,小时,分钟,秒
    private List<ClassifyGoodBean.ClassifyGood> nList;
    private List<HomeBean.SortListBean> sortList;
    private LimitImgAdapter llAdapter;
    private String sortName, atmCode;
    private boolean isFirstVisit = false;//第一次访问
    private ArrayList<Banner> bannerBean = new ArrayList<>();
    private int promotionId;

    private void startRun() {
        timerView.setTime(1, 15, 33);
        timerView.start();
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }

    @Override
    protected void initData() {
        startRun();//定时
        initFragment();//初始化fragment
        initLandButton();//初始button
    }

    /**
     * 读取ATM编码
     */
    private void initgetAddId() {
        try {
            StringBuffer sb = new StringBuffer();
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/SocialSecurityATM/atmCode.txt");
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line = "";
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            br.close();
            atmCode = sb.toString();
            Log.i("aaa", "---homecode--" + atmCode);
            if (!TextUtils.isEmpty(atmCode)) {
                requestAddid(atmCode);
            } else {
                initLanddata();
            }
        } catch (Exception e) {
            e.printStackTrace();
            initLanddata();
        }


//        final OkUtilCallback okUtilCallback = new OkUtilCallback() {
//            @Override
//            public void onMyResponse(String response, int id) {
//                AreaBean bean = gson.fromJson(response, AreaBean.class);
//                if(!bean.getResult().equals("OK")){
//                    BaseApplication.showToast(bean.getResult());
//                }else{
//                    AreaBean.IndexArea a=bean.getArea();
//                    AppConfig.CITY_ID=a.getId();
//                    SPUtils.setStringData(getContext(),SPUtils.AREANAME,a.getName());
//                    initLanddata();//联网获取数据
//                    AppConfig.ATMFVISIT="2";
//                    Log.i("aaa","---a--"+AppConfig.CITY_ID+a.getName());
//                }
//            }
//
//        };
//        String params="longitude="+log+"&latitude="+lat;
//        OKUtilAPI.post(OKUtilAPI.indexaddId, params, okUtilCallback);
    }

    /**
     * @param atmCode 根据编码获取地址ID
     */
    private void requestAddid(String atmCode) {
        String params = "atmNum=" + atmCode;
        OKUtilAPI.post(OKUtilAPI.ATMCODE, params, new OkUtilCallback() {
            @Override
            public void onMyResponse(String response, int id) {
                System.out.println("HuaG=" + response);
                ATMcode bean = gson.fromJson(response, ATMcode.class);
                if (bean.getResult().equals("OK")) {
                    AppConfig.CITY_ID = bean.getArea().getId();
                    AppConfig.WID = bean.getArea().getId();
                    SPUtils.setStringData(getContext(), SPUtils.AREANAME, bean.getArea().getName());
                    initLanddata();//联网获取数据
                    AppConfig.ATMFVISIT = "2";
                    land_h_city.setText(bean.getArea().getName() + ".");
                } else {
                    land_h_city.setText(".");
                    ToastUtil.show(getContext(), bean.getResult(), 3500);
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                ToastUtil.show(getContext(), "网络异常，请手动选择地址", 1500);
            }
        });
    }

    /**
     * 头部商品分类的点击事件
     */
    private void initLandButton() {
        landRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                String tag = (String) (radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()).getTag());
//                AppConfig.SOID = tag;
                String aId;
                switch (checkedId) {

                    case R.id.one:
                        aId = sortList.get(1).getLevelId();
                        sortName = sortList.get(1).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        one.setChecked(false);
                        break;
                    case R.id.two:
                        aId = sortList.get(0).getLevelId();
                        sortName = sortList.get(0).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        two.setChecked(false);
                        break;
                    case R.id.three:
                        aId = sortList.get(2).getLevelId();
                        sortName = sortList.get(2).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        three.setChecked(false);
                        break;
                    case R.id.four:
                        aId = sortList.get(3).getLevelId();
                        sortName = sortList.get(3).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        four.setChecked(false);
                        break;
                    case R.id.five:
                        aId = sortList.get(4).getLevelId();
                        sortName = sortList.get(4).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        five.setChecked(false);
                        break;
                    case R.id.six:
                        aId = sortList.get(5).getLevelId();
                        sortName = sortList.get(5).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        six.setChecked(false);
                        break;
                    case R.id.seven:
                        aId = sortList.get(6).getLevelId();
                        sortName = sortList.get(6).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        seven.setChecked(false);
                        break;
                    case R.id.eight:
                        aId = sortList.get(7).getLevelId();
                        sortName = sortList.get(7).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        eight.setChecked(false);
                        break;
                    case R.id.nine:
                        aId = sortList.get(8).getLevelId();
                        sortName = sortList.get(8).getName();
                        SPUtils.setStringData(getActivity(), SPUtils.LID, aId);
                        requestSortData(aId, sortName);
                        nine.setChecked(false);
                        break;

                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        if (AppConfig.ATMFVISIT.equals("2")) {
            initLanddata();//联网获取数据
        }

    }

    @Override
    public void onPause() {
        super.onPause();
    }

    private void requestSortData(final String lid, final String sortName) {
        Intent intent = new Intent(getActivity(), GoodLandClassifyActivity.class);
        intent.putExtra("sortName", sortName);
        intent.putExtra("classiftId", lid);
        startActivity(intent);
    }

    private void initFragment() {
        festivaFragment = new FestivaFragment();
        fragmentManager = getChildFragmentManager();
        currentFragment = festivaFragment;
        showFragment(festivaFragment);
    }

    private void showFragment(Fragment targetFragment) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (!targetFragment.isAdded()) {
            fragmentTransaction.add(R.id.landFrame, targetFragment).hide(currentFragment).show(targetFragment).commit();
        } else {
            fragmentTransaction.hide(currentFragment).show(targetFragment).commit();
        }
        currentFragment = targetFragment;
    }


    private void initLanddata() {
        if (!NetUtils.isConnected(getContext())) {
            Toast.makeText(getContext(), "请检查你的网络", Toast.LENGTH_SHORT).show();
            landRadio.setVisibility(View.GONE);
        } else {
            mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
            OkUtilCallback okUtilCallback = new OkUtilCallback(mEmptyLayout) {
                @Override
                public void onMyResponse(String response, int id) {
                    System.out.println("response == " +response);
                    homeBean = gson.fromJson(response, HomeBean.class);
                    if ((!AppConfig.RESULT_OK.equalsIgnoreCase(homeBean.getResult())) && homeBean.getLogin()) {
                        mEmptyLayout.setErrorType(EmptyLayout.NO_LOGIN);
                    } else if ((!AppConfig.RESULT_OK.equalsIgnoreCase(homeBean.getResult()))) {
                        BaseApplication.getIntstance().showToast(homeBean.getResult(), Toast.LENGTH_SHORT, 0, Gravity.TOP);
                        landRadio.setVisibility(View.GONE);
                        mEmptyLayout.setErrorType(EmptyLayout.NODATA);
                    } else if ((AppConfig.RESULT_OK.equalsIgnoreCase(homeBean.getResult()))) {
                        landRadio.setVisibility(View.VISIBLE);
                        initGoodsClassify();//物品分类
                        initshoreData();//特色专享
                        initBrandRevelry();//品牌狂欢
                        initLoveGoods();//猜你喜欢
                        initChao();//超值低价
                        initLimitData();
                        initBanner();//头部的viewpager轮播
                        if (AppConfig.CITY_ID == 182) {
                            SPUtils.setStringData(getContext(), SPUtils.AREANAME, "丰城市");
                        } else {
                        }
                        String curName = SPUtils.getStringData(getContext(), SPUtils.AREANAME);
                        land_h_city.setText(curName + ".");
                    }
                }

                @Override
                public void onError(Call call, Exception e, int id) {
                    super.onError(call, e, id);
                    mEmptyLayout.setErrorType(EmptyLayout.NETWORK_ERROR);
                }
            };
            String params = "addrId=" + AppConfig.CITY_ID + "&brandLimit=4" + "&sortLimit=9";
            System.out.println("AppConfig.CITY_ID=="+AppConfig.CITY_ID);
            OKUtilAPI.get(OKUtilAPI.atmhomeurl, params, okUtilCallback);
        }
    }

    private void initBanner() {
        if (homeBean.getBannerList() != null) {
            bannerBean = homeBean.getBannerList();
            frameLayout.removeAllViews();
            ArrayList<Banner> banners = new ArrayList<>();
            for (int i = 0; i < bannerBean.size(); i++) {
                Banner banner = new Banner();
                banner.setImgPath(OKUtilAPI.imgBaseUrl + bannerBean.get(i).getImg());
                banner.setImgUrl(bannerBean.get(i).getImg());
                banner.setLink(bannerBean.get(i).getLink());
                banners.add(banner);
            }
            frameLayout.addView(HomeBannerUtil.getloopviewpager2(getActivity(), banners, "home"));
        }
    }

    private void initshoreData() {
        try {
            if (homeBean.getPromotionList().size() <= 0) {
                fenRecycler.setVisibility(View.GONE);
                Log.i("aaa",homeBean.getPromotionList().size()+"");
                return;
            }
            final List<HomeBean.PromotionListBean.GoodsListBean> guessList = homeBean.getPromotionList().get(0).getGoodsList();
            promotionId = homeBean.getPromotionList().get(0).getId();
            cAdapter.updata(guessList);
            fenRecycler.setNumColumns(5);
            fenRecycler.setVisibility(View.VISIBLE);
            fenRecycler.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Intent intent = new Intent(getActivity(), CommidContentActivity.class);
                    int id = guessList.get(i).getId();
                    intent.putExtra("type", "id");
                    intent.putExtra("id", String.valueOf(id));
                    startActivity(intent);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void initChao() {
        final List<HomeBean.Chaodijia> guessList = homeBean.getChaozhidijia();
        Log.e("ID", "ID===========" +homeBean.getChaozhidijia().size());
        guessAdapter.updata(guessList);
        tejia_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                intent = new Intent(getContext(), CommidContentActivity.class);
                int id = guessList.get(i).getId();
                Log.e("ID", "ID===========" + id);
                intent.putExtra("type", "id");
                intent.putExtra("id", String.valueOf(id));
                startActivity(intent);
            }
        });

    }

    private void initLimitData() {
        final List<HomeBean.XianshiGou.XianshL> brandList;
        try {
            if(homeBean.getXianshiqianggou() == null){
               brandList = new ArrayList<>();
                System.out.println("brandList1");
            }else{
                brandList = homeBean.getXianshiqianggou().getGoodsList();
                System.out.println("brandList2");
            }
            landProAdapter.updata(brandList);
            xianshi_view.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
//        xianshi_view.addItemDecoration(new RecycleViewDivider(getContext(),LinearLayoutManager.VERTICAL,30,getResources().getColor(R.color.bgcolor)));
            landProAdapter.setOnItemClickListener(new LandProAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int i) {
                    Intent intent = new Intent(getContext(), CommidContentActivity.class);
                    int id = brandList.get(i).getId();
                    intent.putExtra("type", "id");
                    intent.putExtra("id", String.valueOf(id));
                    startActivity(intent);
                }

                @Override
                public void onItemLongClick(View v, int position) {

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initGoodsClassify() {
        sortList = homeBean.getSortList();
        String lId = sortList.get(1).getLevelId();
        SPUtils.setStringData(getActivity(), SPUtils.LID, lId);
        one.setText(sortList.get(1).getName());
        one.setTag(sortList.get(1).getLevelId() + "");

        two.setText(sortList.get(0).getName());
        two.setTag(sortList.get(0).getLevelId() + "");

        three.setText(sortList.get(2).getName());
        three.setTag(sortList.get(2).getLevelId() + "");

        four.setText(sortList.get(3).getName());
        four.setTag(sortList.get(3).getLevelId() + "");

        five.setText(sortList.get(4).getName());
        five.setTag(sortList.get(4).getLevelId() + "");

        six.setText(sortList.get(5).getName());
        six.setTag(sortList.get(5).getLevelId() + "");

        seven.setText(sortList.get(6).getName());
        seven.setTag(sortList.get(6).getLevelId() + "");

        eight.setText(sortList.get(7).getName());
        eight.setTag(sortList.get(7).getLevelId() + "");

        nine.setText(sortList.get(8).getName());
        nine.setTag(sortList.get(8).getLevelId() + "");
    }


    private void initLoveGoods() {
        final List<HomeBean.GuessListBean> guessList = homeBean.getGuessList();
        guessAdapter2.updata(guessList);
        buttomView.setLayoutManager(new GridLayoutManager(getContext(), 5, LinearLayoutManager.VERTICAL, false));
        buttomView.addItemDecoration(new DividerGridItemDecoration(getContext()), getResources().getColor(R.color.bgcolor));
        guessAdapter2.setOnItemClickListener(new LandGuessAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                intent = new Intent(getContext(), CommidContentActivity.class);
                int id = guessList.get(position).getId();
                Log.e("ID", "ID===========" + id);
                intent.putExtra("type", "id");
                intent.putExtra("id", String.valueOf(id));
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int position) {

            }
        });
    }

    private void initBrandRevelry() {
        final List<HomeBean.BrandListBean> brandList = homeBean.getBrandList();
        bAdapter.updata(brandList);
        revelry.setLayoutManager(new GridLayoutManager(getContext(), 4, LinearLayoutManager.VERTICAL, false));
        bAdapter.setOnItemClickListener(new BrandRevelryLandAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int i) {
                Intent intent = new Intent(getActivity(), GoodClassifyActivity.class);
                intent.putExtra("brandId", brandList.get(i).getId());
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int position) {

            }
        });
    }

    ChaotejiaAdpter guessAdapter;
    BrandRevelryLandAdapter bAdapter;
    LandGuessAdapter guessAdapter2;
    LandProAdapter landProAdapter;
    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        int width = (int) (TDevice.getScreenWidth() - 40) / 6;
//        Log.i("yu","--width="+width);
        LinearLayout.LayoutParams para = new LinearLayout.LayoutParams(width, width);
        land_xian_ll.setLayoutParams(para);
        if (AppConfig.ATMFVISIT.equals("1")) {
            initgetAddId();//第一次访问通过获取ATM编码
        } else {
            initLanddata();
        }
        guessAdapter = new ChaotejiaAdpter(getContext());
        tejia_view.setAdapter(guessAdapter);
        cAdapter = new ClassifyGoodHomeAdpter(getActivity());
        fenRecycler.setAdapter(cAdapter);
        bAdapter = new BrandRevelryLandAdapter(getContext());
        revelry.setAdapter(bAdapter);
        guessAdapter2 = new LandGuessAdapter(getContext());
        buttomView.setAdapter(guessAdapter2);
        landProAdapter = new LandProAdapter(getContext());
        xianshi_view.setAdapter(landProAdapter);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        Looper = false;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home_land;
    }

    @OnClick({R.id.lifefayout, R.id.tosortList, R.id.land_more, R.id.img_error_layout, R.id.more_brandlist, R.id.land_xian_ll, R.id.tolimit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.lifefayout:
                intent = new Intent(getContext(), LimitTimeGoActivity.class);
                startActivity(intent);
                break;
            case R.id.tosortList:
                String lId = "0";
                SPUtils.setStringData(getActivity(), SPUtils.LID, lId);
                intent = new Intent(getContext(), GoodLandClassifyActivity.class);
                intent.putExtra("sortName", land_h_city.getText().toString() + "特色专享");
                intent.putExtra("promotionId", promotionId);
                Log.i("aaa", "--promotionId--" + promotionId);
                startActivity(intent);
                break;
            case R.id.land_more:
                ((MainActivity) getActivity()).showSortPageFragment();
                landMore.setChecked(false);
                break;
            case R.id.img_error_layout:
                initLanddata();
//                requestSortData(SPUtils.getStringData(getActivity(),SPUtils.LID),sortName);
                break;
            case R.id.more_brandlist:
                intent = new Intent(getContext(), BrandListActivity.class);
                startActivity(intent);
                break;
            case R.id.land_xian_ll:
                intent = new Intent(getContext(), LimitTimeGoActivity.class);
                startActivity(intent);
                break;
            case R.id.tolimit:
                intent = new Intent(getContext(), LimitTimeGoActivity.class);
                startActivity(intent);
                break;
        }
    }
}
